<template>
  <view class="detail">
    <sun-header :title="$t('TransactionsDetails')" :style="getBackground+'backdrop-filter:blur(0px)'"></sun-header>
    <!-- 顶部样式 动态背景 -->
    <view class="top-bg" :style="getBackground">
      <view class="pay-text">
        {{ item.refundStatus ? $t('refunded') : $t(item.paymentStatus) }}
      </view>
    </view>

    <view class="top">
      <view class="unit" style="font-size: 0;" v-if="locale == 'en'">
        <image style="width: 90rpx;height: 90rpx;" src="/static/images/status/money_detail.png" mode="widthFix"></image>
      </view>
      <view class="text" v-if="status == 1 && item.amount"><text v-if="locale == 'zh'">$</text> {{ item.amount / 100 }}
      </view>
    </view>

    <view class="card" :style="'padding:' + cPading + 'px 13px'">
      <view class="lable">{{ $t('DateProcessed') }}</view>
      <view class="value">{{ item.capturedTime }}</view>
      <view class="pay-icon">
        <image v-if="item.paymentStatus == 'success' && !item.refundStatus" src="/static/images/status/success.svg"
          mode="widthFix"></image>
        <image v-if="item.paymentStatus == 'success' && item.refundStatus" src="/static/images/status/back.svg"
          mode="widthFix"></image>
        <image v-if="item.paymentStatus == 'fail'" src="/static/images/status/fail.svg" mode="widthFix"></image>
        <image v-if="
            item.paymentStatus == 'pending' || item.paymentStatus == 'PENDING'
          " src="/static/images/status/wait.svg" mode="widthFix"></image>
      </view>
    </view>
    <view class="card" :style="'padding:' + cPading + 'px 13px'">
      <view class="lable">{{ $t('PaymentChannel') }}</view>
      <view class="value">{{ getPaymentName }}</view>
      <view class="card-icon">
        <image :src="`/static/images/status/${getPaymentImg}.svg`" mode="widthFix"></image>
      </view>
    </view>

    <view class="bottom" :style="'padding:' + cPading + 'px 13px'">
      <view class="title">
        {{ $t('TranscationID') }}
      </view>
      <view class="name">
        {{ item.id }}
      </view>
    </view>
    <!--view v-if="type == 'pay'" class="button" @click="back">
      {{$t('status.btn')}}
    </view-->
	<view v-if="type == 'pay'">
	  <view style="display: flex;justify-content:space-between;padding:0rpx 28rpx;margin-top: 40rpx;margin-bottom: 40rpx;">
		  <view @click="back" class="new_button" :style="'width:'+new_button_width+'rpx;height:'+new_button_height+'rpx;border:4rpx solid #0044B4;background:#0052d9;'">
			  <view v-if="isSmallScreen == false" class="new_button_icon">
				  <image class="new_icon" src="/static/images/status/back_white.png" mode=""></image>
			  </view>
			  <view class="new_button_size">{{$t('button_left_size')}}</view>
		  </view>
		  <view @click="pause_three_seconds" class="new_button" :style="'width:'+new_button_width+'rpx;height:'+new_button_height+'rpx;opacity:'+right_button_opacity+';border:4rpx solid '+right_button_border_color+';background:'+right_button_background_color+';'">
			  <view v-if="isSmallScreen == false" class="new_button_icon">
				  <image class="new_icon" :src="'/static/images/status/'+two_paper_img+''" mode=""></image>
			  </view>
			  <view class="new_button_size" :style="'color:'+button_right_size_color+''">{{button_right_size}}</view>
		  </view>
	  </view>
	  <view class="detail_three_seconds" :style="'color:'+detail_three_seconds_color+''">
		  <view>{{detail_three_seconds_1}}</view>
		  <view>{{detail_three_seconds_2}}</view>
	  </view>
	</view>
    <view v-else>
      <view v-if="item.paymentStatus == 'success' && !item.refundStatus" class="button"
        style="background: #e34d59; margin-top: 30rpx" @click="issueRefund">
        <image src="/static/images/status/rufund.svg" mode="widthFix"></image>
        {{ $t('IssueRefund') }}
      </view>
      <!-- && !item.refundStatus 退款状态 -->
      <view v-if="item.paymentStatus == 'success'" class="button" @click="printCurrent">
        <image src="/static/images/status/printer.svg" mode="widthFix"></image>
        {{ $t('PrintReceipt') }}
      </view>
    </view>

    <!--view class="btn" @click="startRefund" style="color: rgb(227, 77, 89)">
      测试退款刷卡
    </view-->
    <footer-logo v-if="isSmallScreen == false"></footer-logo>

    <view class="dialog" v-if="showInputPwd">
      <view class="mask"></view>
      <view class="modal">
        <view class="d-top">
          <view class="d-title">{{ $t('PasswordIsRequired') }}</view>
          <input class="d-input" @input="getVal" type="safe-password" focus placeholder="" />
        </view>
        <view class="d-bottom">
          <view class="btn" @click="showInputPwd = false" style="color: rgb(0, 0, 0)">
            {{ $t('Cancel') }}
          </view>
          <view class="btn" @click="submit" style="color: rgb(227, 77, 89)">
            {{ $t('Refund') }}
          </view>
        </view>
      </view>
    </view>


    <view class="head-card" v-if="is_dcs_show">
      <!-- <sun-header :title="$t('log.headTitle')"></sun-header> -->
      <view class="img">
        <image v-for="(item,index) in 5" :key="index" class="svg" v-if="index == money_type_icon"
          :src="`/static/images/headCard/hand-card-${index + 1}.svg`" mode="">
        </image>
      </view>
      <view class="t1">Total</view>
      <view class="t2">
        S${{ money | convertNum }}
      </view>
      <view class="t3">
        Tap, Insert, or Swipe to pay
      </view>
      <view class="footer-btn" @click="cancel_dcs">
        Tap to cancel
      </view>
    </view>
	<uqrcode v-if="SOLANA_PAY_QR_URL" ref="SOLANA_PAY_uqrcode" canvas-id="SOLANA_PAY_qrcode" :value="SOLANA_PAY_QR_URL"
	  size="160" hide @complete="uqrcodeComplete"></uqrcode>
  </view>
</template>

<script>
  import sunHeader from '@/components/sun-header/sun-header.vue'
  import api from '@/utils/api/index.js'
  import utils from '@/utils/util.js'
  import newPrint from '@/utils/mixins/newPrint.js'
  import _ from 'loadsh'

  // #ifdef APP-PLUS
  const initSunmi = uni.requireNativePlugin('Hd-InitSunmiModule')
  const saleSmRefund = uni.requireNativePlugin('Hd-RefundModule')
  const saleSmSaleVoid = uni.requireNativePlugin('Hd-SaleVoidModule')
  const saleSm_quxiao = uni.requireNativePlugin('Hd-SaleSmModule')
  // #endif
  import {
    listMock
  } from '../list/listMock.js'
  import {
    mapGetters
  } from 'vuex'
  export default {
    name: 'status',
    components: {
      sunHeader,
    },
    computed: {
      ...mapGetters(['locale']),
      getBackground() {
        let background = 'background:'
        let str = this.item.paymentStatus && this.item.paymentStatus.toLowerCase(),
          color = '#ffffff'
        let refundStatus = this.item.refundStatus || false
        if (str == 'success') {
          color = refundStatus ? '#A000FF' : '#00C260'
        } else if (str == 'fail' || str == 'cancel' || str == 'canceled') {
          color = '#ED0006'
        } else if (str == 'pending' || str == 'PENDING' || str == 'Pending') {
          color = '#F9A000'
        } else {
          color = 'transparent'
        }
        return background + color + ';'
      },
      getPaymentImg() {
        let str = this.item.acquirerTypeAbbreviation && this.item.acquirerTypeAbbreviation.toLowerCase()
        if (str == 'wechat') {
          return 'wechatpay'
        } else if (str == 'alipay') {
          return 'alipay'
        } else if (str == 'mastercard_domestic') {
          return 'Mastercard'
        } else if (str == 'mastercard_international') {
          return 'Mastercard'
        } else if (str == 'dinersclubcard_domestic') {
          return 'DinersClub'
        } else if (str == 'dinersclubcard_international') {
          return 'DinersClub'
        } else if (str == 'amexcard_domestic') {
          return ''
        } else if (str == 'amexcard_international') {
          return ''
        } else if (str == 'visacard_domestic') {
          return 'Visa'
        } else if (str == 'visacard_international') {
          return 'Visa'
        } else if (str == 'unionpay_domestic') {
          return 'UnionPay'
        } else if (str == 'unionpay_international') {
          return 'UnionPay'
        } else if (str == 'jcbcard_domestic') {
          return ''
        } else if (str == 'jcbcard_international') {
          return ''
        } else if (str == 'grab_pay_later') {
          return 'Grabpay'
        } else if (str == 'grab_pay') {
          return 'Grabpay'
        } else if (str == 'paynow') {
          return 'Paynow'
        } else if (str == 'pinelablater') {
          return ''
        } else if (str == 'solana_pay') {
          return 'UpNetwork'
        }
      },
      getPaymentName() {
        let str = this.item.acquirerTypeAbbreviation && this.item.acquirerTypeAbbreviation.toLowerCase()
        if (this.locale == "zh") {
          if (str == 'wechat') {
            return '微信支付'
          } else if (str == 'alipay') {
            return '支付宝'
          } else if (str == 'mastercard_domestic') {
            return '万事达 本地卡'
          } else if (str == 'mastercard_international') {
            return '万事达 外卡'
          } else if (str == 'dinersclubcard_domestic') {
            return 'DinersClub 本地卡'
          } else if (str == 'dinersclubcard_international') {
            return 'DinersClub 外卡'
          } else if (str == 'amexcard_domestic') {
            return 'AmexCard 本地卡'
          } else if (str == 'amexcard_international') {
            return 'AmexCard 外卡'
          } else if (str == 'visacard_domestic') {
            return 'VISA 本地卡'
          } else if (str == 'visacard_international') {
            return 'VISA 外卡'
          } else if (str == 'unionpay_domestic') {
            return '银联国际 本地卡'
          } else if (str == 'unionpay_international') {
            return '银联国际 外卡'
          } else if (str == 'jcbcard_domestic') {
            return 'JCBCard 本地卡'
          } else if (str == 'jcbcard_international') {
            return 'JCBCard 外卡'
          } else if (str == 'grab_pay_later') {
            return 'GrabPay'
          } else if (str == 'grab_pay') {
            return 'GrabPay'
          } else if (str == 'paynow') {
            return 'PayNow'
          } else if (str == 'pinelablater') {
            return ''
          } else if (str == 'solana_pay') {
            return 'UP NETWORK '
          }
        } else {
          if (str == 'wechat') {
            return 'WeChat Pay'
          } else if (str == 'alipay') {
            return 'Alipay+'
          } else if (str == 'mastercard_domestic') {
            return 'Matercard Domestic'
          } else if (str == 'mastercard_international') {
            return 'Matercard International'
          } else if (str == 'dinersclubcard_domestic') {
            return 'DinersClub Domestic'
          } else if (str == 'dinersclubcard_international') {
            return 'DinersClub International'
          } else if (str == 'amexcard_domestic') {
            return 'AmexCard Domestic'
          } else if (str == 'amexcard_international') {
            return 'AmexCard International'
          } else if (str == 'visacard_domestic') {
            return 'VISA Domestic'
          } else if (str == 'visacard_international') {
            return 'VISA International'
          } else if (str == 'unionpay_domestic') {
            return 'UnionPay Domestic'
          } else if (str == 'unionpay_international') {
            return 'UnionPay International'
          } else if (str == 'jcbcard_domestic') {
            return 'JCBCard Domestic'
          } else if (str == 'jcbcard_international') {
            return 'JCBCard International'
          } else if (str == 'grab_pay_later') {
            return 'GrabPay'
          } else if (str == 'grab_pay') {
            return 'GrabPay'
          } else if (str == 'paynow') {
            return 'PayNow'
          } else if (str == 'pinelablater') {

          } else if (str == 'solana_pay') {
            return 'UP NETWORK '
          }
        }

      }


    },
    mixins: [newPrint],
    data() {
      return {
        id: 0,
        type: null, // type = pay 说明是从键盘页面来的
        item: {},
        // item: listMock[0],
        merchantParams: {},
        bluetoothStatus: false,
        currentItem: {},
        showInputPwd: false,
        password: '',
        status: 1, // 1 成功 2失败
        iconW: 100,
        cPading: 90,
        is_shangmi: 0,
        is_void: 0,
        is_today: 0,
        // 刷卡退款参数
        vMainData: {
          amount: 1, // 必传 订单金额（分）
          cardNo: '', // 刷卡后自动回显
          cardExpDate: '', // 卡片到期日期 可忽略
          cardCvv: '', // 卡片CVV签名 可忽略
          tips: 0, // 可忽略
          orderId: '', // 订单id 非必传
          oriReferenceNo: '', // 必传 取刷卡成功后的 referenceNo 406070000195
          oriVoucherNo: '', // 必传 取刷卡成功后的 stan 000271
        },
        dcs_base64: '',
        money_type_icon: 0, // 5个图片	
        is_dcs_show: false,
        yi_dcs: null,
        money: '0.00',
		button_right_size:'',
		//is_pause_three_seconds:0,
		two_paper_img:'two_paper_1.png',
		right_button_border_color:'#BF000F',
		right_button_background_color:'#E34D59',
		right_button_opacity:'1',
		button_right_size_color:'#ffffff',
		detail_three_seconds_1:'',
		detail_three_seconds_2:'',
		detail_three_seconds_color:'#E34D59',
		isSmallScreen:false,
		new_button_width:'',
		new_button_height:'',
		SOLANA_PAY_QR_URL: '',
		SOLANA_PAY_DATA: {},
      }
    },
    onShow() {
      uni.getSystemInfo({
        success: (res) => {
          let h = res.windowHeight
          if (h < 580) {
            this.iconW = 80
            this.cPading = 0
          } else if (h >= 580 && h < 620) {
            this.cPading = 5
            this.iconW = 90
          } else {
            this.cPading = 10
            this.iconW = 100
          }

          if (res.deviceBrand == 'sunmi') {
            this.is_shangmi = 1
          } else {
            this.is_shangmi = 0
          }
          // this.winH = res.windowHeight
        },
      })
    },
    onLoad(e) {
      let _this = this;
	  //e.id = "1339228574611537920";
	  //e.type = "pay";
      _this.id = e.id;
      _this.type = e.type || null;
	  _this.is_pause_three_seconds = 0;
	  _this.button_right_size = _this.$t('button_right_size_1');
	  _this.detail_three_seconds_1 = _this.$t('detail_three_seconds_1_1');
	  _this.detail_three_seconds_2 = _this.$t('detail_three_seconds_1_2');
	  uni.setStorageSync('is_cli_pause_three_seconds', 'no');
	  
	  let systemInfo = uni.getSystemInfoSync('systemInfo');
		if (systemInfo.deviceModel == "P2_SE") {
			_this.isSmallScreen = true;
			_this.new_button_width = '328';
			_this.new_button_height = '100';
		} else {
			_this.isSmallScreen = false;
			_this.new_button_width = '328';
			_this.new_button_height = '202';
		}
		
      let o = {id: e.id};
      api.selectTransactionDetailById(o).then((res) => {
        if (res.code == '000000') {
          let data = res.data;
          console.log(data);
          _this.item = data;
          let JsonBigstring = require('json-bigint')({
            storeAsString: true,
          })
          _this.money = _this.item.amount / 100;
          if (data.refundStatus == "" || data.refundStatus == null) {
            _this.is_void = 0;
          } else {
            _this.is_void = 1;
          }
          let is_today = _this.isToday(new Date(data.capturedTime));
          if (is_today == true) { //当天
            _this.is_today = 1;
          } else {
            _this.is_today = 0;
          }
          console.log("is_today: " + _this.is_today);
		  console.log(data);
          _this.vMainData.amount = data.amount;
          _this.vMainData.oriReferenceNo = data.acquirerTransactionId;
          _this.vMainData.oriTransactionType = data.transactionType;
		  if(data.dcsCardPrintInfoDto && data.dcsCardPrintInfoDto.stan){
			  _this.vMainData.oriVoucherNo = data.dcsCardPrintInfoDto.stan;
		  }
		  
          let storeInfo = uni.getStorageSync('storeInfo');
		  if(storeInfo){
			  console.log("storeInfo");
			  _this.merchantParams = {
			    merchantId: storeInfo.dcsMerchantId, // 默认值  肯定DCS
			    terminalId: storeInfo.dcsTerminalId, // 默认值  肯定DCS
			    subMerchantCity: storeInfo.dcsSubMerchantCity,
			    subMerchantId: storeInfo.dcsSubMerchantId,
			    subTerminalId: storeInfo.dcsSubTerminalId,
			    subMerchantName: storeInfo.dcsSubMerchantName,
			    subMerchantCountryCode: storeInfo.dcsSubMerchantCountryCode
			  };
		  }else{
			  console.log("storeInfo_empty");
		  }
		  if(_this.type == "pay"){
			  if(_this.item.acquirerType == "SOLANA_PAY"){
				  _this.SOLANA_PAY_QR_URL = data.upnetworkDownloadUrl;
				  _this.SOLANA_PAY_DATA = data;
				  console.log(_this.SOLANA_PAY_QR_URL)
				  console.log(_this.SOLANA_PAY_DATA)
				  _this.$refs.SOLANA_PAY_uqrcode.remake({
					success: () => {
						
					},
					fail: err => {
					}
				  });
			  }else{
				  _this.startPrint(_this.item);
				 setTimeout(() => {
					let is_cli_pause_three_seconds = uni.getStorageSync('is_cli_pause_three_seconds');
					if(is_cli_pause_three_seconds == 'no'){
						uni.setStorageSync('is_cli_pause_three_seconds','two_dayin');
						_this.right_button_opacity = '0.3';
						_this.detail_three_seconds_1 = _this.$t('detail_three_seconds_3_1');
						_this.detail_three_seconds_2 = _this.$t('detail_three_seconds_3_2');
						_this.detail_three_seconds_color = '#0052D9';
						setTimeout(() => {
						  uni.navigateBack();
						}, 3000);
					}
				 }, 3000); 
			  }
		  }
        }
      });
    },
    filters: {
      convertNum(num) {
        if (num == '0.00') {
          return num
        }
        // 正则转换为千分位 1,234.56
        let n = num.toString().replace(/(\d)(?=(\d{3})+\.)/g, '$1,')
        return n
      },
    },
    methods: {
      // 判断是否开启蓝牙
      judgeBluetooth() {
        // 主机模式
        return new Promise((resolve, reject) => {
          // mode: 'central',
          uni.openBluetoothAdapter({
            success: (r) => {
              console.log('蓝牙初始化成功')
              // 获取蓝牙的匹配状态
              uni.getBluetoothAdapterState({
                success: function(row) {
                  console.log('蓝牙状态：', row.available)
                  if (row.available) {
                    resolve()
                  } else {
                    // 请开启蓝牙
                    this.remindOpenBluetooth()
                    reject()
                  }
                },
                fail: function(err) {
                  // 请开启蓝牙
                  this.remindOpenBluetooth()
                  reject()
                },
              })
            },
            fail: (err) => {
              // 请开启蓝牙
              console.log('蓝牙初始化失败' + JSON.stringify(err))
              this.remindOpenBluetooth()
              reject()
            },
          })
        })
      },
      // 提示用户需要开启蓝牙
      remindOpenBluetooth() {
        this.bluetoothStatus = true
        uni.onBluetoothAdapterStateChange((blu) => {
          if (blu.available) {
            this.bluetoothStatus = false
          }
        })
      },
      issueRefund() {
        this.showInputPwd = true;
      },
      async submit() {
        if (!this.password) {
          uni.showToast({
            icon: 'none',
            title: this.$t('PasswordIsRequired'),
          })
          return;
        }
        let o = {
          voidPassword: this.password,
        }
        utils.showLoading()

        let res = await api.validateRefundPassword(o)
        uni.hideLoading()
        if (res.code == '000000') {
          this.returnPayment()
        } else {
          utils.showText(res.message)
        }
      },
      cancel_dcs() {
        clearInterval(this.yi_dcs);
        this.yi_dcs = null;
        this.is_dcs_show = false;
        saleSm_quxiao.cancelCheckCard();
      },
      // 发起退款
      async returnPayment() {
        let _this = this;
        if (_this.item.acquirerType == 'DCS_CARD_NOW_PAY') {
          _this.is_dcs_show = true;
          _this.yi_dcs = null;
          let i = 0
          _this.yi_dcs = setInterval(() => {
            _this.money_type_icon = i
            i++
            if (i > 4) {
              i = 0
            }
          }, 2000);
          _this.startRefund()
        } else {
          utils.showLoading()
          let o = {
            acquirerType: _this.item.acquirerType,
            paymentTerminalRequestVo: {
              transactionId: _this.item.id + '',
              amount: _this.item.amount,
              actionType: 'REFUND',
            },
          }
          let res = await api.paymentPay(o)
          uni.hideLoading()
          if (res.code == '000000') {
            utils.showSuccess('Success')
            _this.showInputPwd = false;
            _this.printCurrent();
            /*
          setTimeout(() => {
            uni.navigateBack({
              delta: 1,
            })
          }, 1000)
		  */
          } else {
            utils.showText(res.message)
          }
        }
      },
      /**
       * startRefund
       */

      startRefund() {
        let _this = this;
        console.log(this.vMainData);
        console.log('走到的退款');
        if (this.is_today == 1) {
          _this.cli_void();
        } else {
          _this.cli_refund();
        }
      },
      cli_void() {
        let _this = this;
        saleSmSaleVoid.saleVoid(_this.vMainData, (result) => {
          console.log(result);
          console.log("==========================")
          if (result['code'] == -100002) {
            _this.$global.addLog(JSON.stringify(_this.merchantParams), "merchantParams");

            initSunmi.setConfig(_this.merchantParams, (config) => {
              console.log("config==========config");
              console.log(config);
              if (config.code == 200) {
                _this.$global.addLog(JSON.stringify(config), "config");
                initSunmi.signOn((sign) => {
                  console.log("signOn==========signOn");
                  console.log(sign);
                  _this.$global.addLog(JSON.stringify(sign), "signOn");
                  if (sign.code == 200) {
                    _this.cli_void();
                  } else {
                    _this.error_info(sign.data);
                  }
                });
              } else {
                _this.error_info(sign.data);
              }
            });
          } else if (result['code'] == -100003) {
            initSunmi.signOn((sign) => {
              console.log("signOn==========signOn");
              console.log(sign);
              _this.$global.addLog(JSON.stringify(sign), "signOn");
              if (sign.code == 200) {
                _this.cli_void();
              } else {
                _this.error_info(sign.data);
              }
            });
          } else {
            console.log(result)
            console.log('ssssssssssssssssss')
            let rdata = result['data']
            if (
              (result['code'] === 201 && rdata['cardNo']) ||
              (result['code'] === 201 && rdata['uuid'])
            ) {
              if (result['code'] === 201 && rdata['cardNo']) {
                _this.vMainData['cardNo'] = rdata['cardNo']
              }
              _this.setManualKeyVoid();
            } else {
              _this.$global.addLog(JSON.stringify(result))
              uni.showModal({
                title: '温馨提示',
                content: rdata.data,
                showCancel: false,
              })
            }
            _this.is_dcs_show = false;
            clearInterval(_this.yi_dcs);
            _this.yi_dcs = null;
          }
        });
      },
      setManualKeyVoid() {
        let _this = this;
        saleSmSaleVoid.setManualKey(_this.vMainData, (result) => {
          let rdata = result['data']
          console.log('!!!!!!!!!!!')
          console.log(result)
          if (rdata.sale) {
            _this.error_info(rdata.sale);
          } else {
            if (result.code == '204' && result.message == 'onAppFinalSelect') {
              saleSmSaleVoid.confirmAppFinalSelect(true);
            } else if (result.code == '204' && result.message == 'onConfirmCardNo') {
              saleSmSaleVoid.confirmCardNo(true);
            } else {
              if (result.code == '205' && rdata.status == 'success' && rdata.result.answerCode == '00') {
                console.log(444444444444)
				saleSmSaleVoid.cardOff();
                _this.paySuccess(rdata)
              } else {
                _this.$global.addLog(JSON.stringify(result))
                uni.showModal({
                  title: '温馨提示',
                  content: rdata,
                  showCancel: false,
                });
              }
            }
          }
        })
      },
      cli_refund() {
        let _this = this;
        initSunmi.setRefundAndPreAuthFlag(true, false, (res) => {
          if (res['code'] == 200) {
            saleSmRefund.startRefund(this.vMainData, (result) => {
              console.log(result);
              console.log("==========================")
              if (result['code'] == -100002) {
                _this.$global.addLog(JSON.stringify(this.merchantParams), "merchantParams");
                initSunmi.setConfig(this.merchantParams, (config) => {
                  console.log("config==========config");
                  console.log(config);
                  if (config.code == 200) {
                    _this.$global.addLog(JSON.stringify(config), "config");
                    initSunmi.signOn((sign) => {
                      console.log("signOn==========signOn");
                      console.log(sign);
                      _this.$global.addLog(JSON.stringify(sign), "signOn");
                      if (sign.code == 200) {
                        _this.startRefund();
                      } else {
                        _this.error_info(sign.data);
                      }
                    });
                  } else {
                    _this.error_info(sign.data);
                  }
                });
              } else if (result['code'] == -100003) {
                initSunmi.signOn((sign) => {
                  console.log("signOn==========signOn");
                  console.log(sign);
                  _this.$global.addLog(JSON.stringify(sign), "signOn");
                  if (sign.code == 200) {
                    _this.startRefund();
                  } else {
                    _this.error_info(sign.data);
                  }
                });
              } else {
                console.log(result)
                console.log('ssssssssssssssssss')
                let rdata = result['data']
                if (
                  (result['code'] === 201 && rdata['cardNo']) ||
                  (result['code'] === 201 && rdata['uuid'])
                ) {
                  if (result['code'] === 201 && rdata['cardNo']) {
                    _this.vMainData['cardNo'] = rdata['cardNo']
                  }
                  _this.setManualKeyRefund()
                } else {
                  _this.$global.addLog(JSON.stringify(result))
                  uni.showModal({
                    title: '温馨提示',
                    content: rdata.data,
                    showCancel: false,
                  })
                }
                _this.is_dcs_show = false;
                clearInterval(_this.yi_dcs);
                _this.yi_dcs = null;
              }
            });
          } else {
            _this.error_info(res.message);
          }
        });
      },
      setManualKeyRefund() {
        let _this = this;
        saleSmRefund.setManualKey(_this.vMainData, (result) => {
          let rdata = result['data']
          console.log('!!!!!!!!!!!')
          console.log(result)
          if (rdata.sale) {
            _this.error_info(rdata.sale);
          } else {
            if (result.code == '204' && result.message == 'onAppFinalSelect') {
              saleSmRefund.confirmAppFinalSelect(true);
            } else if (result.code == '204' && result.message == 'onConfirmCardNo') {
              saleSmRefund.confirmCardNo(true);
            } else {
              if (result.code == '205' && rdata.status == 'success' && rdata.result.answerCode == '00') {
                console.log(555555555555);
				saleSmRefund.cardOff();
                _this.paySuccess(rdata);
              } else {
                _this.$global.addLog(JSON.stringify(result))
                uni.showModal({
                  title: '温馨提示',
                  content: rdata,
                  showCancel: false,
                });
              }
            }
          }
        })
      },
      paySuccess(data) {
        let _this = this;
        console.log('@@@@@@@@@@@@@')
        console.log(data)
        let store = uni.getStorageSync('storeInfo') || {}

        let o = {
          acquirerType: this.item.acquirerType,
          paymentTerminalRequestVo: {
            transactionId: this.item.id + '',
            amount: this.item.amount,
            actionType: 'REFUND',
          },
        }

        api.paymentPay(o).then((res) => {
          console.log(res, '-------------------------')
          console.log(res.code, '-------------------------')
          if (res.code == '000000') {
            let refundId = res.data.refundId
            console.log(refundId)
            let oo = {
              refundId: refundId,
              refundStatus: 'success',
              errorMessage: 'sucess',
              acquirerRefundId: this.vMainData.oriReferenceNo, // 取什么值？
            }
            console.log('&&&&&&&&&&&&&&&&&')
            console.log(oo)

            api.updateDcsCardPayRefundTransaction(oo).then((rres) => {
              console.log(rres, '-------------------------')
              if (rres.code == '000000') {
                utils.showSuccess('Success')
                _this.showInputPwd = false;
                setTimeout(() => {
                  /*
                uni.navigateBack({
                  delta: 1,
                })
				*/
                  _this.printCurrent();
                }, 1000)
              } else {
                utils.showText(result.message)
              }
            })
          } else {
            utils.showText(result.message)
          }
        })
      },
      getVal(e) {
        console.log(e)
        this.password = e.detail.value
      },
      printCurrent() {
        //let item = _.cloneDeep(this.item)
        let _this = this;
        let o = {
          id: _this.id
        };
        console.log(o);
        api.selectTransactionById(o).then((res) => {
          if (res.code == '000000') {

            let data = res.data;
            _this.item = data;

            console.log(_this.item);
            let is_void = false;
            let times = 1;
            if (_this.item.refundStatus == "" || _this.item.refundStatus == null) {

            } else {
              is_void = true;
              times = 2;
            }
            if (_this.item.acquirerType == "DCS_CARD_NOW_PAY") {
              _this.newPrintTextDcs(_this.item, times, is_void, _this.dcs_base64);
            } else {
              _this.newPrintText(_this.item, times, true, is_void);
            }
          }


        });
      },
      error_info(data) {
        this.is_dcs_show = false;
        clearInterval(this.yi_dcs);
        this.yi_dcs = null;
        uni.showModal({
          title: '温馨提示',
          content: data,
          showCancel: false,
        });
      },
      back() {
        uni.navigateBack();
      },
      isToday(date) {
        const today = new Date();
        return date.getFullYear() === today.getFullYear() &&
          date.getMonth() === today.getMonth() &&
          date.getDate() === today.getDate();
      },
	  pause_three_seconds(){
		  let _this = this;
		  let is_cli_pause_three_seconds = uni.getStorageSync('is_cli_pause_three_seconds');
		  if(is_cli_pause_three_seconds == 'no'){
			  uni.setStorageSync('is_cli_pause_three_seconds', 'yes');
			  _this.button_right_size = _this.$t('button_right_size_2');
			  _this.two_paper_img = 'two_paper_2.png';
			  _this.right_button_border_color = '#9A9A9A';
			  _this.right_button_background_color = '#F1F1F1';
			  _this.button_right_size_color = '#6B6B6B';
			  _this.detail_three_seconds_1 = _this.$t('detail_three_seconds_2_1');
			  _this.detail_three_seconds_2 = _this.$t('detail_three_seconds_2_2');
			  _this.detail_three_seconds_color = '#E34D59';
			  setTimeout(() => {
			  	uni.navigateBack();
			  }, 3000);
		  }
	  },
	  startPrint(item) {
	    let _this = this;
		console.log(item.acquirerType);
	    if (item.acquirerType == 'DCS_CARD_NOW_PAY') {
	      _this.newPrintTextDcs(item, 2, false, _this.dcs_base64)
	    } else {
	      if (item.acquirerType == "SOLANA_PAY") {
	        _this.$refs.SOLANA_PAY_uqrcode.toTempFilePath({
	          success: res => {
	            const path = plus.io.convertLocalFileSystemURL(res.tempFilePath)
	            const fileReader = new plus.io.FileReader()
	            fileReader.readAsDataURL(path)
	            fileReader.onloadend = (res) => {
	              //console.log(res.target.result,'base64图片流') //输出base64内容
	              _this.newPrintText(item, 2, false, false, '', res.target.result);
	            }
	    
	          }
	        });
	      } else {
	        _this.newPrintText(item, 2, '');
	      }
	    }
	  },
	  uqrcodeComplete(val) {
		let _this = this;
	    // 二维码生成完成 { success: true | false }
	    //console.log('二维码生成完成',val)
	    //console.log(this.SOLANA_PAY_DATA);
	    //this.success_url(this.SOLANA_PAY_DATA);
	    // 如果 val.success 为 true 则表示二维码生成成功 可以执行其他操作
		
		_this.startPrint(_this.SOLANA_PAY_DATA);
		setTimeout(() => {
			let is_cli_pause_three_seconds = uni.getStorageSync('is_cli_pause_three_seconds');
			if(is_cli_pause_three_seconds == 'no'){
				uni.setStorageSync('is_cli_pause_three_seconds','two_dayin');
				_this.right_button_opacity = '0.3';
				_this.detail_three_seconds_1 = _this.$t('detail_three_seconds_3_1');
				_this.detail_three_seconds_2 = _this.$t('detail_three_seconds_3_2');
				_this.detail_three_seconds_color = '#0052D9';
				setTimeout(() => {
				  uni.navigateBack();
				}, 3000);
			}
		}, 3000); 
	  },

    },
  }
</script>

<style lang="scss" scoped>
  @import 'detail.scss';

  .uni-modal__textarea {
    height: 70rpx;
    text-align: left;
    width: 100%;
    box-sizing: border-box;
    padding-left: 56rpx;
    background: transparent !important;
    margin-bottom: 20rpx;
    font-size: 40rpx;
  }
</style>